﻿@page "/SysTimeInterval/Create"
@using SelfService.ViewModel.SysTimeIntervalVMs;
@inherits BasePage

<ValidateForm @ref="VForm" Model="@_model" OnValidSubmit="@Submit">
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
        <BootstrapInput @bind-Value="@_model.Entity.Name"/>
        <TimePickerBody @bind-Value="@_model.Entity.StartTime"/>
        <BootstrapInput @bind-Value="@_model.Entity.StartTime" TValue="TimeSpan" Formatter="@FormatterSpanString"/>
        <TimePickerBody @bind-Value="@_model.Entity.EndTime"/>
        <BootstrapInput @bind-Value="@_model.Entity.EndTime" TValue="TimeSpan" Formatter="@FormatterSpanString"/>
    </Row>
    <div class="modal-footer table-modal-footer">
        <Button Color="Color.Primary" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Close"]" OnClick="OnClose"></Button>
        <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Create"]" IsAsync="true"></Button>
    </div>
</ValidateForm>

@code {

    private readonly SysTimeIntervalVm _model = new SysTimeIntervalVm();
    private ValidateForm VForm { get; set; }


    protected override async Task OnInitializedAsync()
    {

        await base.OnInitializedAsync();
    }

    private string FormatterSpanString(TimeSpan ts)
    {
        return ts.ToString("hh\\:mm\\:ss");
    }


    private async Task Submit(EditContext context)
    {
        await PostsForm(VForm, "/api/SysTimeInterval/add", (s) => "Sys.OprationSuccess");
    }

    public void OnClose()
    {
        CloseDialog();
    }

}
